﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Module.Core.BusinessLogic;
using Module.Core.EntitiesInfo;
using Module.Core.LoginSystem.Commons.Framwork;

namespace Web.Cms.ConfigKeyword
{
    public partial class ConfigEdit : AdminPage
    {
        int ConfigId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request.QueryString["ConfigId"] != null && Request.QueryString["ConfigId"] != "")
                    ConfigId = Convert.ToInt32(Request.QueryString["ConfigId"]);
                TxtConfigValue_VN.Height = 170;
                TxtConfigValue_VN.Width = 560;
                if (!Page.IsPostBack)
                {
                    if (ConfigId > 0)
                    {
                        btnEdit.Visible = true;
                        ConfigKeywordInfo configKeywordInfo = ConfigKeywordBL.Select(ConfigId);
                        if (configKeywordInfo != null)
                        {
                            txtConfigKey.Text = configKeywordInfo.ConfigKey;
                            TxtConfigValue_VN.Text = configKeywordInfo.ConfigValue_VN;
                            txtConfigKey.Enabled = false;
                        }
                    }
                    else
                        btnAddNew.Visible = true;
                }
            }
            catch (Exception ex) { ltrJump.Text = ex.Message; }
        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                ConfigKeywordInfo info = new ConfigKeywordInfo();
                info.ConfigId = ConfigId;
                info.ConfigKey = txtConfigKey.Text;
                info.ConfigValue_VN = TxtConfigValue_VN.Text;
                ConfigKeywordBL.Update(info);               
                ltrJump.Text = "Bạn đã thay đổi thành công !";                
            }
            catch (Exception ex) { ltrJump.Text = ex.Message; }
        }
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            ConfigKeywordInfo info = new ConfigKeywordInfo();
            info.ConfigKey = txtConfigKey.Text;
            info.ConfigValue_VN = TxtConfigValue_VN.Text;
            info.ConfigIdLang = 0;
            info.Status = 1;
            ConfigKeywordBL.Insert(info);           
            ltrJump.Text = "Bạn đã thêm mới thành công !";           
        }
    }
}